Skip to content

allow list files to exit gracefully when there are too many files and add a non recursive version to limit return files#19

Merged
m-y-mo merged 5 commits intomainfrom
limit_list_file
Dec 12, 2025
Merged

allow list files to exit gracefully when there are too many files and add a non recursive version to limit return files#19
m-y-mo merged 5 commits intomainfrom
limit_list_file

Conversation

@m-y-mo
Copy link
Copy Markdown
Contributor

@m-y-mo m-y-mo commented Dec 12, 2025

No description provided.

… add a non recursive version to limit return files
Copilot AI review requested due to automatic review settings December 12, 2025 10:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds graceful handling for directories with too many files and introduces a non-recursive file listing option. It implements a configurable file limit (default 100) via environment variable to prevent performance issues when listing large directories, and provides an alternative non-recursive listing function for better control over output size.

  • Adds FILE_LIMIT_FOR_LIST_FILES environment variable with default value of 100
  • Implements list_files_non_recursive tool to list files in a single directory level only
  • Adds file count check in list_files that returns an informative error when limit is exceeded

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/seclab_taskflows/toolboxes/local_file_viewer.yaml Adds FILE_LIMIT_FOR_LIST_FILES environment variable configuration
src/seclab_taskflows/mcp_servers/local_file_viewer.py Implements file limit checking, adds recursive parameter to _list_files, and introduces list_files_non_recursive tool

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 79 to 89
if entry.is_dir():
continue
if not recursive:
dirname = remove_root_dir(entry.filename)
if Path(dirname).parent == Path(root_dir):
results.append(dirname)
filename = remove_root_dir(entry.filename)
if root_dir and not is_subdirectory(root_dir, filename):
continue
if not recursive and Path(filename).parent != Path(root_dir):
continue
results.append(filename)
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic error in the _list_files function: when an entry is a directory, the code continues to process it as a file on line 84. When entry.is_dir() is True, the code should skip to the next iteration after handling the directory case, but currently it falls through and processes the directory entry again as if it were a file. The logic should add a 'continue' statement after line 83 to prevent processing directories as files. Additionally, line 84 onwards will execute for both files and directories in the current implementation.

Copilot uses AI. Check for mistakes.
source_path = sanitize_file_path(source_path, [LOCAL_GH_DIR])
if not source_path or not source_path.exists():
return f"Invalid {owner} and {repo}. Check that the input is correct or try to fetch the repo from gh first."
content = _list_files(source_path, path, recursive=False)
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message suggests using 'list_files_non_recursive' but this won't solve the problem if the non-recursive listing itself has more than FILE_LIMIT_FOR_LIST_FILES files in a single directory. The non-recursive function should also check and enforce the file limit. Consider applying the same limit check in list_files_non_recursive to prevent it from returning an excessive number of results.

Suggested change
content = _list_files(source_path, path, recursive=False)
content = _list_files(source_path, path, recursive=False)
if len(content) > FILE_LIMIT_FOR_LIST_FILES:
return f"Too many files to display in {owner}/{repo} at path {path} ({len(content)} files)."

Copilot uses AI. Check for mistakes.
Comment thread src/seclab_taskflows/mcp_servers/local_file_viewer.py Outdated
Comment thread src/seclab_taskflows/mcp_servers/local_file_viewer.py Outdated
m-y-mo and others added 2 commits December 12, 2025 10:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings December 12, 2025 10:34
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

repo: str = Field(description="The name of the repository"),
path: str = Field(description="The path to the directory in the repository")) -> str:
"""
List the files of a directory from a local GitHub repository non-recursively.
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a spelling error in the docstring. "non recursively" should be hyphenated as "non-recursively" for proper English grammar.

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +83
if not recursive:
dirname = remove_root_dir(entry.filename)
if Path(dirname).parent == Path(root_dir):
results.append(dirname)
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for handling directories in non-recursive mode has an issue. When a directory matches the parent path condition (line 82), the code appends it to results but then continues to line 84 which skips to the next entry. However, this means that if recursive is False and we're NOT in a directory entry, the code will still process files normally. The problem is that directory entries are being added to the results list, but the function should only list files and subdirectories at the specified level, not intermediate directory paths. This could lead to unexpected results where directory paths are included in what should be a file listing.

Suggested change
if not recursive:
dirname = remove_root_dir(entry.filename)
if Path(dirname).parent == Path(root_dir):
results.append(dirname)
# In non-recursive mode, do not append directories to results

Copilot uses AI. Check for mistakes.
if root_dir and not is_subdirectory(root_dir, filename):
continue
if not recursive and Path(filename).parent != Path(root_dir):
continue
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected. Line 89 has extra indentation (8 spaces instead of 4), which breaks Python's indentation consistency. This should be aligned with the if statement on line 88.

Suggested change
continue
continue

Copilot uses AI. Check for mistakes.
Comment on lines 155 to +182
return json.dumps(content, indent=2)


Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file limit check doesn't apply to the non-recursive version. This creates an inconsistency: if a user hits the limit with the recursive version and follows the suggestion to use list_files_non_recursive, they could still get thousands of files back if the directory has many files at that level. Consider adding the same file limit check to list_files_non_recursive for consistency and to prevent performance issues.

Suggested change
return json.dumps(content, indent=2)
if len(content) > FILE_LIMIT_FOR_LIST_FILES:
return f"Too many files to display in {owner}/{repo} at path {path} ({len(content)} files)."
return json.dumps(content, indent=2)

Copilot uses AI. Check for mistakes.
return f"Invalid {owner} and {repo}. Check that the input is correct or try to fetch the repo from gh first."
content = _list_files(source_path, path)
if len(content) > FILE_LIMIT_FOR_LIST_FILES:
return f"Too many files to display in {owner}/{repo} at path {path} ({len(content)} files). Try using `list_files_non_recursive` instead."
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message suggests using list_files_non_recursive but wraps the function name in backticks, which may not render properly in all contexts where this error is displayed. Consider using either plain text or ensuring the output format properly handles markdown formatting.

Suggested change
return f"Too many files to display in {owner}/{repo} at path {path} ({len(content)} files). Try using `list_files_non_recursive` instead."
return f"Too many files to display in {owner}/{repo} at path {path} ({len(content)} files). Try using list_files_non_recursive instead."

Copilot uses AI. Check for mistakes.
@m-y-mo m-y-mo merged commit 50ebf73 into main Dec 12, 2025
9 checks passed
@m-y-mo m-y-mo deleted the limit_list_file branch December 12, 2025 14:45
kiandadban pushed a commit to kiandadban/seclab-taskflows that referenced this pull request May 4, 2026
…list_file

allow list files to exit gracefully when there are too many files and add a non recursive version to limit return files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants